package site.immonkey.ftptest.beans;

import java.util.ArrayList;
import java.util.List;

public class FtpResponse {
	private int code = -1;
	private List<String> infos;

	public FtpResponse() {}

	public FtpResponse(int code) {
		this.code = code;
	}

	public FtpResponse(int code, List<String> infos) {
		super();
		this.code = code;
		this.infos = infos;
	}

	public boolean success() {
		return code >= 200 && code < 300;
	}
	
	public String getLastInfo() {
		return infos.get(infos.size() - 1);
	}
	
	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public List<String> getInfos() {
		return infos;
	}

	public void setInfos(List<String> infos) {
		this.infos = infos;
	}

	public void putInfo(String info) {
		if (infos == null) infos = new ArrayList<>();
		infos.add(info);
	}

	@Override
	public String toString() {
		return "Response [code=" + code + ", info=" + infos + "]";
	}
}
